#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <limits>
#include <climits>
using namespace std;

const bool DISPLAY_TIME = false;

vector<vector<int> > getCost(vector<int> &a) {
	int n = a.size();
	vector<vector<int> > cost(n, vector<int>(n));
	for (int i = 0; i < n; ++i) {
		cost[i][i] = 0;
		int pos = i;
        int cntL = 0;
        int cntR = 0;
        int sumL = 0;
        int sumR = 0;
		for (int j = i + 1; j < n; ++j) {
			++cntR;
			sumR += a[j] - a[pos];
			if (pos < (i + j) / 2) {
				int delta = a[pos + 1] - a[pos];

				++cntL;
				sumL += cntL * delta;

				sumR -= cntR * delta;
				--cntR;

				++pos;
			}
			cost[i][j] = sumL + sumR;
		}
	}
	return cost;
}

int solve(vector<int> &a, int k) {
	int startTime = clock();
	vector<vector<int> > cost = getCost(a);
	int n = a.size();
	vector<vector<int> > len(n, vector<int>(n + 1));
	vector<vector<int> > f(n, vector<int>(n + 1, INT_MAX / 2));
	for (int i = 0; i < n; ++i) {
		for (int j = 1; j <= n; ++j) {
			f[i][j] = cost[0][i];
			len[i][j] = i + 1;
			for (int last = 1; last <= i; ++last) {
				if (j > 1) {
					int t = f[i - last][j - 1] + cost[i - last + 1][i];
					if (f[i][j] > t) {
						f[i][j] = t;
						len[i][j] = last;
					}
				} 
			}
		}
	}
	// for (int i = 0; i < n; ++i) {
	// 	for (int j = i; j < n; ++j) {
	// 		cerr << cost[i][j] << " ";
	// 	}
	// 	cerr << endl;
	// }
	// for (int i = 0; i < n; ++i) {
	// 	for (int j = 1; j <= k; ++j) {
	// 		cerr << f[i][j] << " ";
	// 	}
	// 	cerr << endl;
	// }
	if (DISPLAY_TIME) {
		cerr << "time: " << (double(clock() - startTime) / CLOCKS_PER_SEC) << endl;
	}
	return f[n - 1][k];
}

int solve_n2logn(vector<int> &a, int k) {
	int startTime = clock();
	vector<vector<int> > cost = getCost(a);
	int n = a.size();
	vector<vector<int> > len(n, vector<int>(n + 1));
	vector<vector<int> > f(n, vector<int>(n + 1, INT_MAX / 2));
	for (int i = 0; i < n; ++i) {
		for (int j = 1; j <= n; ++j) {
			f[i][j] = cost[0][i];
			len[i][j] = i + 1;
			int maxLast = i;
			if (j > 1 && maxLast > len[i][j - 1]) {
				maxLast = len[i][j - 1];
			}
			int minLast = 1;
			for (int last = minLast; last <= maxLast; ++last) {
				if (j > 1) {
					int t = f[i - last][j - 1] + cost[i - last + 1][i];
					if (f[i][j] > t) {
						f[i][j] = t;
						len[i][j] = last;
					}
				} 
			}
		}
	}
	if (DISPLAY_TIME) {
		cerr << "time: " << (double(clock() - startTime) / CLOCKS_PER_SEC) << endl;
	}
	return f[n - 1][k];
}

int solve_n2(vector<int> &a, int k) {
	int startTime = clock();
	vector<vector<int> > cost = getCost(a);
	int n = a.size();
	vector<vector<int> > len(n, vector<int>(n + 1));
	vector<vector<int> > f(n, vector<int>(n + 1, INT_MAX / 2));
	for (int j = 1; j <= n; ++j) {
		f[0][j] = 0;
		len[0][j] = 1;
	}
	for (int i = 0; i < n; ++i) {
		f[i][1] = cost[0][i];
		len[i][1] = i + 1;
	}
	for (int i = 1; i < n; ++i) {
		for (int j = n; j >= 0; --j) {
			f[i][j] = cost[0][i];
			len[i][j] = i + 1;
			int maxLast = i;
			if (i > 0 && maxLast > len[i - 1][j] + 1) {
				maxLast = len[i - 1][j] + 1;
			}
			int minLast = 1;
			if (j + 1 <= n && minLast < len[i][j + 1]) {
				minLast = len[i][j + 1];
			}
			for (int last = minLast; last <= maxLast; ++last) {
				if (j > 1) {
					int t = f[i - last][j - 1] + cost[i - last + 1][i];
					if (f[i][j] > t) {
						f[i][j] = t;
						len[i][j] = last;
					}
				} 
			}
		}
	}
	if (DISPLAY_TIME) {
		cerr << "time: " << (double(clock() - startTime) / CLOCKS_PER_SEC) << endl;
	}
	return f[n - 1][k];
}


int main() {
	int n, k, i, x;
	vector <int> a;
	for(scanf("%d%d", &n, &k), i=0; i<n; scanf("%d", &x), a.push_back(x), i++);
	sort(a.begin(), a.end());
	printf("%d.0\n", solve_n2(a, k));

	/*
	int N = 4000;
	for (int n = N; n <= N; ++n) {
		cout << "n = " << n << endl;
		for (int k = N - 10; k <= N; ++k) {
			vector<int> a(n);
		    for (int i = 0; i < n; ++i) {
		    	//a[i] = rand();
		    	a[i] = i < n / 2 ? i * 100 : 1e9 + i;
		    }
		    sort(a.begin(), a.end());

		    // for (int i = 0; i < n; ++i) {
		    // 	cout << a[i] << " ";
		    // }
		    // cout << endl;

		    long long r2 = solve_n2logn(a, k);
		    long long r3 = solve_n2(a, k);
		    long long r1 = r2;//solve(a, k);

		    bool ok = r1 == r2 && r2 == r3;
		    if (ok) {
		    	//cout << ".";
		    } else {
		    	cout << "!";
		    	cout << n << " " << k << endl;
				cout << r1 << endl;
		    	cout << r2 << endl;
		    	cout << r3 << endl;
		    	return 0;
		    }
		}
	}
*/
	return 0;
}